package com.sias.spring.mybatis;

import com.sias.sogra.mapper.UserMapper;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;

import java.util.Set;

/**
 * @author 吴文杰
 * @version 1.0
 * @createTime 2023-05-30 15:45:17
 */
public class SograScanner extends ClassPathBeanDefinitionScanner {

  public SograScanner(BeanDefinitionRegistry registry) {
    super(registry);
  }

  @Override
  protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
    return beanDefinition.getMetadata().isInterface();
  }

  @Override
  protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
    Set<BeanDefinitionHolder> beanDefinitionHolders = super.doScan(basePackages);
    for (BeanDefinitionHolder beanDefinitionHolder : beanDefinitionHolders) {
      BeanDefinition beanDefinition = beanDefinitionHolder.getBeanDefinition();
      beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(beanDefinition.getBeanClassName());
      beanDefinition.setBeanClassName(SograFactoryBean.class.getName());
    }
    return beanDefinitionHolders;
  }
}
